package com.zsd.android.common.retrofit

import io.reactivex.Observer
import io.reactivex.disposables.Disposable

abstract class BaseSubscribe<T>(disposables: ArrayList<Disposable>) : Observer<T> {

     private val disposables: ArrayList<Disposable> = disposables

     override fun onSubscribe(d: Disposable) {
          disposables.add(d)
     }

     override fun onError(e: Throwable) {
          if (e is ApiException) {
               onError(e)
          }
     }

     override fun onComplete() {
          for (disposable in disposables) {
               if (disposable != null && !disposable.isDisposed) {
                    disposable.dispose()
               }
          }
    }

     abstract fun onError(e: ApiException)
}